/**
 * Created by ㅋㅋElsa on 2017/8/22.
 */
layui.define(['jquery', 'layer','paging', 'code','form','element'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var inspnum = getQueryString("inspnum");

    paging.init({
        url: contextPath + "/history/const/inspdclr/" + inspnum, //地址
        elem: '#con', //内容容器
        type: 'GET',
        //new
        key: '#s_type',
        value: '#s_value',
        params: { //发送到服务端的参数
        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调
        },
    });

    $("body").on("click",".constmoress",function(){
        var inspdate = $(this).data('id');
        tampdata = $(this).data('id');

        $.get('ConstDetailsCheck.html', null, function(ConstDetailsCheck) {
            layer.open({
                type: 1,
                title: '报检单详情',
                content: ConstDetailsCheck,
                area: ['auto', '600px'],
                maxmin: false,
                success:function (layero,index) {
                    layero.find("#closex").on("click",function () {
                        layer.closeAll();
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/project/const/inspdclr/info",
                        data: {"inspnum": inspnum, "inspdate": inspdate},
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {

                            if(data.status == "报检单填写无误"){
                                $('#confrimlabel').html("确认检验日期");
                                $('input[name="confirmtime"]').show();
                                form.render();
                            }else{
                                $('#confrimlabel').html("");
                                $('input[name="confirmtime"]').hide();
                                form.render();
                            }

                            if(data.inspopinion == "通过"){
                                $('#rectnum').html("");
                                $('input[name="rectnum"]').hide();
                                $('#norect').show();
                                $('#rect').hide();
                                form.render();
                            }else if(data.inspopinion == "需整改"){
                                $('#rectnumlabel').html("整改编号");
                                $('input[name="rectnum"]').show();
                                $('#norect').hide();
                                $('#rect').show();
                                form.render();
                            }else{
                            }
                            
                            $('input[name="shipname"]').attr("value",data.shipname);
                            $('input[name="figurenum"]').attr("value",data.figurenum);
                            $('input[name="ccpronum"]').attr("value",data.ccpronum);
                            $('input[name="apnttime"]').attr("value",data.apnttime);
                            $('input[name="inspname"]').attr("value",data.inspname);
                            $('textarea[name="insppro"]').val(data.insppro);
                            $('input[name="cc"]').attr("value",data.cc);
                            $('input[name="rq1"]').attr("value",data.rq1);
                            if(data.cdopinion){
                                $('input[name="cdopinion"]').attr("value",data.cdopinion);
                                $('input[name="cd"]').attr("value",data.cd);
                                $('input[name="rq2"]').attr("value",data.rq2);
                            }
                            if(data.status){
                                $('input[name="status"]').attr("value",data.status);
                                $('input[name="confirmtime"]').attr("value",data.confirmtime);
                                $('input[name="ycs1"]').attr("value",data.ycs1);
                                $('input[name="rq3"]').attr("value",data.rq3);
                            }
                            if(data.inspopinion){
                                $('input[name="inspopinion"]').attr("value",data.inspopinion);
                                $('input[name="ycs2"]').attr("value",data.ycs2);
                                $('input[name="rq4"]').attr("value",data.rq4);
                                if(data.inspopinion=="通过"){
                                    $('textarea[name="opncontent"]').val(data.opncontent);
                                }else if(data.inspopinion=="需整改"){
                                    $('input[name="rectnum"]').attr("value",data.rectnum);
                                    if(data.confirmresult=="未完成"||data.confirmresult=="完成"){
                                        $('input[name="confirmresult"]').attr("value",data.confirmresult);
                                    }
                                    $('input[name="ycs3"]').attr("value",data.ycs3);
                                    $('input[name="rq5"]').attr("value",data.rq5);
                                    $('textarea[name="rectopinion"]').val(data.rectopinion);
                                    $('textarea[name="rectresult"]').val(data.rectresult);
                                }else{
                                }
                                if(data.cdopn){
                                    $('input[name="cdopn"]').attr("value",data.cdopn);
                                    $('input[name="cdopndate"]').attr("value",data.cdopndate);
                                }
                                if(data.ccopn){
                                    $('input[name="ccopn"]').attr("value",data.ccopn);
                                    $('input[name="ccopndate"]').attr("value",data.ccopndate);
                                }
                            }

                            $('#su').on('click',function () {
                                window.open('../../../../print/const/ConstInspdclr/ConstInspdclr.html?inspnum='+inspnum+'&inspdate='+inspdate);
                            });

                            if(data.rectnum){
                                $('#sus').show();
                                $('#sus').on('click',function () {
                                    window.open('../../../../print/const/ConstQualityTable/ConstQualityTable.html?inspnum='+inspnum+'&inspdate='+inspdate);
                                });
                            }

                        },
                        error:function (e) {
                        }
                    });

                },
                yes: function(index) {
                    console.log(index);
                },
                full: function(elem) {
                    var win = window.top === window.self ? window : parent.window;
                    $(win).on('resize', function() {
                        var $this = $(this);
                        elem.width($this.width()).height($this.height()).css({
                            top: 0,
                            left: 0
                        });
                        elem.children('div.layui-layer-content').height($this.height() - 95);
                    });
                }
            });
            form.render();
        });
    });

    $('body').on('click', '#close', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });

    $('#search').on('click', function() {
        var type = $('#search_type').val();
        var value = $('#search_value').val();
        $('#s_type').attr("value",type);
        $('#s_value').attr("value",value);
        if( value === '' || value.length === 0) {
            layer.msg('请输入关键字！',{
                time:2000
            });
            return ;
        }

        paging.get({
            value: value,
            type: type
        });
    });

    $('#showall').on('click', function() {
        $('#search_type').val("");
        $('#search_value').val("");
        $('#s_type').removeAttr("value");
        $('#s_value').removeAttr("value");
        form.render();
        paging.get({
            value: null,
            type: null
        });
    });

    exports('ConstCheckList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});